<?php  
      $time=date("Y-m-d H:i:s");  
	  echo “现在时间”.$time;
	  echo "<br>";

$con = mysql_connect("localhost","root","xxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("xx2020", $con);
$result = mysql_query("SELECT * FROM token
         WHERE name='hua'");
		 $row = mysql_fetch_array($result);
		 $hqtime=$row['gqtime'];
		 if ( $scha=strtotime($time)-strtotime($hqtime)>7100)
		 {echo "大于7100"."<br>";
		 
		 define("APPID", "xxxxxxxxxxxx");//你的appid
         define("APPSECRET", "xxxxxxxxxxxxxx");//你的appsecret
        $appId = APPID;
        $appSecret = APPSECRET;
 
        //请求地址
        $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appId&secret=$appSecret";
        //发送get请求，并将返回的json转化为数组，提取出token
        $ch = curl_init();//c初始化一个cURL会话
        curl_setopt($ch, CURLOPT_URL, $url);//将URL设置为我们需要的URL
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);//获取json返回数据
        curl_close($ch);
        $jsonInfo = json_decode($output, true);
        $token= $jsonInfo["access_token"];
		echo $token."</br>";
		//更新数据
		mysql_query("UPDATE token SET tkzhi= '$token'
WHERE name= 'hua'");
mysql_query("UPDATE token SET gqtime = '$time'
WHERE name= 'hua'");
		 
		  }
		 else
		 {echo "小于700"."<br>";
		 echo  $token=$row['tkzhi'];
		 }
		 



mysql_close($con);


?>


	